package day20171222;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * Created by JAVA on 2017/12/29.
 */
public class Test {
    public static void main(String[] args) throws IOException {
        String path="F:\\test.zip";
        ZipFile zipFile=new ZipFile(path);
        Enumeration entries=zipFile.entries();
        ZipFile zipFile1=null;
        while (entries.hasMoreElements()){
            ZipEntry zipEntry = (ZipEntry) entries.nextElement();
            System.out.println(zipEntry.getName());
            //创建test文件夹
            File testFile=new File("F:\\test");
            testFile.mkdir();
            //字节流 读文件 写文件
            InputStream fileInputStream=zipFile.getInputStream(zipEntry);
            FileOutputStream fileOutputStream=new FileOutputStream(
                    new File("F:\\test\\"+zipEntry.getName()));
            byte[]date=new byte[1024];
            while(fileInputStream.read(date)!=-1){
                fileOutputStream.write(date);
            }
            fileInputStream.close();
            fileOutputStream.close();
        }
    }
}
